package com.zpark.resume.controller;

import com.zpark.resume.common.ResponseResult;
import com.zpark.resume.common.StatusCode;
import com.zpark.resume.entity.Education;
import com.zpark.resume.entity.Recommend;
import com.zpark.resume.service.IEducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: com.zpark.resume.controller
 * @ClassName: EducationController
 * @Description:
 * @author: RZS
 * @date: 2023/6/1  17:53
 */
@RestController
@CrossOrigin
@RequestMapping("/education")
public class EducationController {

    @Autowired
    private IEducationService educationService;

    /**
     * 根据cv_id查询education数据
     * @param id cv_id
     * @return
     */
    @PostMapping("/find_by_cv_id/{id}")
    public ResponseResult<List<Education>> findRecommendByCvId(@PathVariable("id") Integer id){
        // 调用业务层接口查询数据
        List<Education> educations = educationService.findByCvId(id);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), educations);
    }

    /**
     * 添加教育经历
     * @param education
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<Void> addEdu(@RequestBody Education education){
        // 调用业务层接口
        educationService.addEducation(education);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }

    /**
     * 修改教育经历
     * @param education
     * @return
     */
    @PostMapping("/update")
    public ResponseResult<Void> changeEdu(@RequestBody Education education){
        // 调用业务层接口
        educationService.changeEducationById(education);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }

    /**
     * 删除教育经历
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult<Void> removeEdu(@PathVariable("id") Integer id){
        // 调用业务层接口
        educationService.removeEducationById(id);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }
}
